package com.ljkj.blockpay.presenter;

import android.content.Context;
import android.content.IntentFilter;

import androidx.annotation.NonNull;

import com.kongzue.baseokhttp.HttpRequest;
import com.kongzue.baseokhttp.listener.JsonResponseListener;
import com.kongzue.baseokhttp.util.JsonList;
import com.kongzue.baseokhttp.util.JsonMap;
import com.kongzue.baseokhttp.util.Parameter;
import com.ljkj.blockpay.basedata.BasePresenter;
import com.ljkj.blockpay.basedata.BasePresenterImpl;
import com.ljkj.blockpay.basedata.BaseView;
import com.ljkj.blockpay.network.ApiToCConfig;
import com.ljkj.blockpay.presenter.inter.SFZinterface;

/**
 * Created by yp on 2022/3/2
 */
public class SFZPresenter extends BasePresenterImpl<SFZinterface.SFZinterfaceView> implements SFZinterface.SFZinterfacePresenter {

    public int tagPage = 1;
//     * tagPage
// *      1,绑定手机
// *      2,邮箱页面
// *      3,安全验证页面
// *      4.交易密码

    public SFZPresenter(@NonNull Context context, @NonNull SFZinterface.SFZinterfaceView view) {
        super(context, view);
    }

    public String getTitle(){
        String title = "";
        switch (tagPage){
            case 1:
                title = "绑定手机号";
                break;
            case 2:
                title = "绑定邮箱";
                break;
            case 3:
            case 4:
                title = "安全验证";
                break;
        }
        return title;
    }

    public String getNotice(){
        String notice = "";
        switch (tagPage){
            case 1:
                notice = "为了您的账户安全，请及时绑定手机号";

                break;
            case 2:
                notice = "为了您的账户安全，请及时绑定邮箱";
                break;
            case 3:
            case 4:
                notice = "交易密码作为支付验证重要凭证，请谨慎操作";
                break;
        }
        return notice;
    }

    /**
     * 绑定账号
     */
    @Override
    public void bindAccount() {
        HttpRequest.POST(getContext(), ApiToCConfig.USER_BINDING_ACCOUNT, new Parameter(), new JsonResponseListener() {
            @Override
            public void onResponse(JsonMap main, Exception error) {
                if (main.getInt("code") == 0){
                    JsonMap data = main.getJsonMap("data");
                    getView().bindSuccess(data);
                }
            }
        });
    }

    @Override
    public void verifycode(String countryCode,Integer tempCode) {
        JsonMap jsonMap = new JsonMap();
        jsonMap.put("countryCode",countryCode);
        jsonMap.put("tempCode",tempCode);
        HttpRequest.JSONPOST(getContext(), ApiToCConfig.URL_SEND_CODE, jsonMap, new JsonResponseListener() {
            @Override
            public void onResponse(JsonMap main, Exception error) {
                if (main.getInt("code") == 0){
                    String data = main.getString("data");
                    getView().verifySucess(jsonMap);
                }
            }
        });
    }

}
